import React, { Component } from 'react';
import Axios from 'axios';
import { apiPrefix } from 'shared/api';
import Td from './Td';
import './index.less';
import SureButton from '../SureButton';

class Education extends Component {
  constructor(props) {
    super(props);
    this.state = {
      education: this.props.data,
      informationInput: [],
    };
  }
  componentDidMount() {
    const api = `${apiPrefix}api/v1/roster/dynamics`;
    Axios.get(api)
      .then(((response) => {
        const arr = response.data.data.filter(value =>
          value.name === '学历');
        console.log(arr);
        this.setState({ informationInput: response.data.data });
        console.log(this.state.informationInput);
      }));
    // console.log(this.state.informationInput);
  }
  addNewTd=() => {
    const { education } = this.state;
    const arr = education;
    arr.push({});
    this.setState({ education: arr });
  }
  delTd=(index) => {
    const { education } = this.state;
    const arr = education;
    arr.splice(index, 1);
    this.setState({ education: arr });
  }
  render() {
    const { education, informationInput } = this.state;
    console.log(education);
    console.log(informationInput);
    return (
      <div>
        <table className="education-table">
          <thead>
            <tr>
              <th colSpan="8" className="remind">说明： 毕业时间不能 小于 入学时间</th>
            </tr>
            <tr>
              <th>序号</th>
              <th>入学时间</th>
              <th>毕业时间</th>
              <th>毕业院校</th>
              <th>专业</th>
              <th>学历</th>
              <th>毕业证书号</th>
              <th><button className="excelButton" onClick={this.addNewTd}>添加一行</button></th>
            </tr>
          </thead>
          <tbody>
            {
              education.map((value, index) => (
                <tr key={index}>
                  <Td value={value} index={index} delTd={() => this.delTd(index)} />
                </tr>
              ))
            }
          </tbody>
        </table>
        <SureButton />
      </div>
    );
  }
}

export default Education;
